using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[CreateAssetMenu(menuName = "Data/State/Player/PlayerHit", fileName = "PlayerHit")]
public class PlayerState_Hit : PlayerState
{
    public override void Enter()
    {
        base.Enter();
        // 移动受到影响，速度变为一半
        Player.Instance.SetPlayerMoveEffect(0.5f);
    }
    
    //
    public override void Exit()
    {
        base.Exit();
        // 移动影响恢复正常
        Player.Instance.SetPlayerMoveEffect(1);
        
        // 受伤状态解除
        Player.Instance.IsHit = false;
    }
    
    //
    public override void LogicUpdate()
    {
        base.LogicUpdate();
        // 动作结束
        if (isAnimationFinished)
        {
            // 玩家死亡
            if (Player.Instance.IsDeath)
            {
                stateMachine.SwitchState(stateMachine.stateTable[typeof(PlayerState_Death)]);
            }
            stateMachine.SwitchState(stateMachine.stateTable[typeof(PlayerState_Idle)]);
        }
        
    }
    
    //
    public override void PhysicalUpdate()
    {
        base.PhysicalUpdate();
        PlayerControl.Instance.Move();
    }
}
